package apiwork.mina.httpserver;

import java.util.Map;
import java.util.Map.Entry;

import com.linkage.util.SystemUtil;

/**
 * A HTTP request message.
 * 
 */
public class HttpRequestMessage {

	private Map<String, String[]> headers = null;

	private String context = null;
	
	public void setHeaders(Map<String, String[]> headers) {
		this.headers = headers;
	}

	public Map<String, String[]> getHeaders() {
		return headers;
	}

	public String getContext() {
		return context;
	}

	public void setContext(String context) {
		this.context = context;
	}

	public String getParameter(String name) {
		String[] param = headers.get("@".concat(name));
		return param == null ? "" : param[0];
	}

	public String[] getParameters(String name) {
		String[] param = headers.get("@".concat(name));
		return param == null ? new String[] {} : param;
	}

	public String[] getHeader(String name) {
		return headers.get(name);
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();

		for (Entry<String, String[]> e : headers.entrySet()) {
			str.append(e.getKey() + " : " + SystemUtil.strArrayToString(e.getValue(), ',')
					+ "\n");
		}
		if (null != context) str.append(context+"\n");
		return str.toString();
	}
}
